package com.pxmeta.app.controller.community;

import com.pxmeta.circle.entity.UserCircle;
import com.pxmeta.circle.service.IUserCircleService;
import com.pxmeta.common.core.domain.AjaxResult;
import com.pxmeta.user.entity.User;
import com.pxmeta.user.entity.dto.CreateBotDTO;
import com.pxmeta.user.service.IUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 机器人
 * 前端控制器
 */
@RestController
@RequestMapping("/bot")
@RequiredArgsConstructor
public class BotController {

    private final IUserService userService;
    private final IUserCircleService userCircleService;

    /**
     * 创建机器人
     * @return
     */
    @PostMapping("/createBot")
    public AjaxResult createBot(@RequestBody CreateBotDTO dto){
        User user = new User();
        user.setIsRobot(1);
        user.setAvatar(dto.getAvatar());
        user.setNickname(dto.getName());
        userService.save(user);
        UserCircle userCircle = new UserCircle();
        userCircle.setCircleId(dto.getCircleId());
        userCircle.setUserId(user.getId());
        userCircle.setNickname(dto.getName());
        userCircleService.joinCircle(userCircle,false);
        return AjaxResult.success();
    }




}
